package com.xin.data.simbapesa.activity;

import android.content.Intent;
import android.view.LayoutInflater;
import android.widget.Toast;

import com.xin.data.simbapesa.R;
import com.xin.data.simbapesa.analysis.libs.RateLib;
import com.xin.data.simbapesa.api.PU;
import com.xin.data.simbapesa.base.BaseActivity;
import com.xin.data.simbapesa.databinding.SimbaScoreActivityBinding;
import com.xin.data.simbapesa.utils.LogUtil;
import com.xin.data.simbapesa.utils.ResUtils;
import com.xin.data.simbapesa.utils.ViewUtils;

public class SimbaScoreActivity extends BaseActivity<SimbaScoreActivityBinding> {


    int score;

    @Override
    protected SimbaScoreActivityBinding initViewBinding(LayoutInflater inflater) {
        return SimbaScoreActivityBinding.inflate(inflater);
    }

    @Override
    protected void initView() {

        binding.tvBtn2.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            finish();
        });
        binding.tvClose.setOnClickListener(v -> {
            ViewUtils.viewScale(v);
            finish();
        });
        binding.tvBtn1.setOnClickListener(view -> {
            ViewUtils.viewScale(view);
            toNext();
        });

    }

    @Override
    protected void initData() {
        UP_TYPE1 = PU.P65;
        UP_TYPE2 = PU.P66;
    }

    void toNext() {
        score = binding.tvRating.getProgress();
        if (score <= 0) {
            Toast.makeText(getActivity(), ResUtils.s(R.string.score_hit1), Toast.LENGTH_LONG).show();
            return;
        }
        LogUtil.e("me", "score->" + score);
        PU.userBuriedPoint(PU.P69, score+"");
        if (score >= 4) {
            RateLib.INSTANCE.launchFlow(this, aBoolean -> {
                LogUtil.e("me", "launchFlow->" + aBoolean);
                return null;
            });
        } else {
            Intent intent = new Intent(getActivity(), SimbaFeedbackActivity.class);
            intent.putExtra("score", score);
            startActivity(intent);
        }
        finish();
    }


}
